package com.ea.controller.back;

import com.ea.api.controller.admin.LogisticsInfoApi;
import com.ea.common.enums.OperationResultCode;
import com.ea.common.exception.ServiceException;
import com.ea.common.response.JsonResult;
import com.ea.common.util.TypeConversionToJson;
import com.ea.domain.dto.LogisticInfoDTO;
import com.ea.domain.entity.LogisticDetailInfo;
import com.ea.domain.query.LogisticQueryDTO;
import com.ea.domain.query.OrderManageQueryDTO;
import com.ea.service.ILogisticInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 物流信息表 前端控制器
 * </p>
 *
 * @author 电器商城
 * @since 2022-11-29
 */
@RestController
@RequestMapping("/electric/back/logistic")
public class LogisticInfoController implements LogisticsInfoApi {

    @Autowired
    private ILogisticInfoService logisticInfoService;

    @Override
    @PostMapping("/info/list")
    public JsonResult getLogisticInfoList(@RequestBody LogisticQueryDTO queryDTO) {
        return JsonResult.doSuccessful(logisticInfoService.getLogisticInfoList(queryDTO));
    }

    @Override
    @GetMapping("/change/status")
    public JsonResult updateLogisticInfoList(@RequestParam("logisticId") Long logisticId, @RequestParam("status")Integer status) {
        if (logisticId == null || status == null) {
            throw new ServiceException(OperationResultCode.PARAMETER_ERROR);
        }
        logisticInfoService.updateLogisticStatus(logisticId, status);
        return JsonResult.updateSuccessFul();
    }

    @Override
    @GetMapping("/info/detail")
    public JsonResult getLogisticDetailList(@RequestParam("logisticId") Long logisticId) {
        if (logisticId == null) {
            throw new ServiceException(OperationResultCode.PARAMETER_ERROR);
        }
        LogisticInfoDTO logisticInfoDTO = logisticInfoService.getLogisticDetailInfoList(logisticId);
        return JsonResult.querySuccessFul(logisticInfoDTO);
    }


}
